#!/usr/bin/env python
#-*-encoding:utf-8-*-
'''
Created on 2015年7月24日

@author: chenyongbing
'''
import sys,os
#current_dir = os.path.dirname(__file__)
current_dir = os.path.split(os.path.realpath(__file__))[0]

basePath = os.path.join(current_dir,'../../')
sys.path.append(basePath)
from base.retail_datas import myRetailDatas
from base.zhimind_datas import myZhimindDatas
from base.time_method import myTimeMethod

#days = ['2015-01-01','2015-02-01','2015-03-01','2015-04-01','2015-05-01','2015-06-01']

days = myTimeMethod.get_slist_between_st_et('2015-08-01', '2015-08-20')

ndatas = {}
for day in days:
    
    datas = myZhimindDatas.get_target_from_rank_stats_by_group(timeType='day', groupType=4, st=day, et=day, targetList=['ent_cust_cnt','visit_cnt'])
    for group , data in datas.items():
        if group not in ndatas.keys():
            ndatas[group] = {}
        ndatas[group][day] = data


print ','.join(['门店ID','门店名','公司','行业','省份','城市']+days+['顾客/客流'])

groupsInfo =  myRetailDatas.get_all_groups_info()

for group , gdatas in ndatas.items():
    
    if int(group) in groupsInfo.keys():
        groupInfo = groupsInfo[int(group)]
    else:
        print 'group %s not found.'%group
        continue
    
    group_name = groupInfo['name']
    prov = groupInfo['province']
    city = groupInfo['city']
    comp_type = groupInfo['comp_type']
    comp_name = groupInfo['comp_name']
    
    dmsg = [str(group),group_name,comp_name,comp_type,prov,city]
    ent_cust_cnt_list = []
    visit_cnt_list = []
    all_cnt_list = []
    for day in days:
        if day not in gdatas.keys():
            ent_cust_cnt = '-'
            visit_cnt = '-'
        else:
            ent_cust_cnt = gdatas[day]['ent_cust_cnt']
            visit_cnt = gdatas[day]['visit_cnt']
        ent_cust_cnt_list.append(str(ent_cust_cnt))
        visit_cnt_list.append(str(visit_cnt))
        all_cnt_list.append(str(ent_cust_cnt))
        all_cnt_list.append(str(visit_cnt))
    print ','.join(dmsg+all_cnt_list)
        
    #print ','.join(dmsg+ent_cust_cnt_list+['顾客'])
    #print ','.join(dmsg+visit_cnt_list+['客流'])
        
        
            
    
    
    